package tenumn.energytech.registrys.pipeline;

import io.github.uicdb.liba.api.register.BlockEntityTypeHolder;
import io.github.uicdb.liba.api.register.BlockHolder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import tenumn.energytech.EnergyTech;

import java.util.function.BiConsumer;

public class WireRegistry {
    public static BlockHolder<WireBlock> wireBlock = EnergyTech.LAZY_REGISTRY.block("wire", WireBlock::new)
            .axe()
            .pickaxe()
            .state(WireRegistry.pipeModel())
            .propertie(BlockBehaviour.Properties::noOcclusion)
            .build();
    public static BlockEntityTypeHolder<WireBlockEntity> wireBlockEntity = EnergyTech.LAZY_REGISTRY.blockEntity("wire", WireBlockEntity::new)
            .withBlocks(wireBlock).build();
    public static BlockHolder<HeartPipeBlock> heartPipeBlock = EnergyTech.LAZY_REGISTRY.block("heart_pipe", HeartPipeBlock::new)
            .axe()
            .pickaxe()
            .state(WireRegistry.pipeModel())
            .propertie(BlockBehaviour.Properties::noOcclusion)
            .build();
    public static BlockEntityTypeHolder<HeartPipeBlockEntity> heartPipeBlockEntity = EnergyTech.LAZY_REGISTRY.blockEntity("heart_pipe", HeartPipeBlockEntity::new)
            .withBlocks(heartPipeBlock).build();

    public static BiConsumer<BlockStateProvider, BlockHolder<?>> pipeModel() {
        return (provider, blockHolder) -> {
            var models = provider.models();
            var pipe = blockHolder.get();
            provider.getMultipartBuilder(blockHolder.get())
                    .part().modelFile(models.getExistingFile(modLoc("block/" + pipe.getRegistryName().getPath()))).addModel().end()
                    .part().modelFile(models.getExistingFile(modLoc("block/" + pipe.getRegistryName().getPath() + "_part"))).uvLock(false).addModel().condition(BlockStateProperties.NORTH, true).end()
                    .part().modelFile(models.getExistingFile(modLoc("block/" + pipe.getRegistryName().getPath() + "_part"))).uvLock(false).rotationY(90).addModel().condition(BlockStateProperties.EAST, true).end()
                    .part().modelFile(models.getExistingFile(modLoc("block/" + pipe.getRegistryName().getPath() + "_part"))).uvLock(false).rotationY(180).addModel().condition(BlockStateProperties.SOUTH, true).end()
                    .part().modelFile(models.getExistingFile(modLoc("block/" + pipe.getRegistryName().getPath() + "_part"))).uvLock(false).rotationY(270).addModel().condition(BlockStateProperties.WEST, true).end()
                    .part().modelFile(models.getExistingFile(modLoc("block/" + pipe.getRegistryName().getPath() + "_part"))).uvLock(false).rotationX(90).addModel().condition(BlockStateProperties.DOWN, true).end()
                    .part().modelFile(models.getExistingFile(modLoc("block/" + pipe.getRegistryName().getPath() + "_part"))).uvLock(false).rotationX(270).addModel().condition(BlockStateProperties.UP, true).end();
        };
    }

    private static ResourceLocation modLoc(String path) {
        return new ResourceLocation(EnergyTech.ID, path);
    }

    public static void init() {

    }
}
